package com.example.entity;

import lombok.Data;

@Data
public class Notice {
    private String id;
    private String title;         // 公告标题
    private String content;       // 公告内容
    private Date publishtime;     // 发布时间
}
公告Mapper接口（NoticeMapper）

        package com.example.mapper;

import com.example.entity.Notice;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface NoticeMapper {
    @Select("SELECT * FROM notice")
    List<Notice> getAllNotices();

    int insertNotice(Notice notice);
    int updateNotice(Notice notice);
    int deleteNoticeById(String id);
}
公告Service层（NoticeService）

        package com.example.service;

import com.example.entity.Notice;
import com.example.mapper.NoticeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoticeService {
    @Autowired
    private NoticeMapper noticeMapper;

    public List<Notice> getAllNotices() {
        return noticeMapper.getAllNotices();
    }

    public void addNotice(Notice notice) {
        noticeMapper.insertNotice(notice);
    }

    public void updateNotice(Notice notice) {
        noticeMapper.updateNotice(notice);
    }

    public void deleteNotice(String id) {
        noticeMapper.deleteNoticeById(id);
    }
}
公告Controller层（NoticeController）
        package com.example.controller;

import com.example.entity.Notice;
import com.example.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

        import java.util.List;

@RestController
@RequestMapping("/api/notice")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;

    @GetMapping
    public List<Notice> getAllNotices() {
        return noticeService.getAllNotices();
    }

    @PostMapping
    public void addNotice(@RequestBody Notice notice) {
        noticeService.addNotice(notice);
    }

    @PutMapping
    public void updateNotice(@RequestBody Notice notice) {
        noticeService.updateNotice(notice);
    }

    @DeleteMapping("/{id}")
    public void deleteNotice(@PathVariable String id) {
        noticeService.deleteNotice(id);
    }
}